package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-24
 * Time: 8:18
 */
//用lambda
public class Demo6 {
    public static void main(String[] args) throws InterruptedException {

        //lambda表达式实现一个类 实现了runnable接口,由于是lambda实现类,不用返回值,但是如果是lambda实现函数,则一定要返回值
        Thread t = new Thread(()->{
            while(true){
                System.out.println("i am thread");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"yzyThread");

        t.start();

        while(true){
            System.out.println("i am main");
            Thread.sleep(5000);
        }
    }
}

